package exercise;

public class Test02 {
    int tribonacci1(int n) {
        //int[] f = new int[n+1];
        if(n == 0){
            return 0 ;
        }
        if(n <= 2){
            return 1;
        }
        int a = 1;
        int b = 1;
        int c = 2;
        int d = 0;
        while(n-2>0){
            d = a + b + c;
            a = b;
            b = c;
            c = d;
            n--;
        }
        return b;
    }
    public int tribonacci(int n) {
        int[] f = new int[n+1];
        if(n == 0){
            return 0 ;
        }
        if(n <= 2){
            return 1;
        }
        f[1] = 1;
        f[2] = 1;
        for(int i = 3;i<=n;i++){
            f[i] = f[i-1] + f[i-2] + f[i-3];
        }
        return f[n];
    }
}
